package com.cy.pj.sys.web.controller;

import com.cy.pj.common.pojo.JsonResult;
import com.cy.pj.sys.pojo.SysMenu;
import com.cy.pj.sys.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/menu/")
@RestController//如果只写controller这个注解的话在进行crud操作的时候需要写RepustBody注解
//如果是这个RestController注解的话就不需要写RepustBody注解
public class SysMenuController {
    @Autowired
    private SysMenuService sysMenuService;

    @PutMapping
    public  JsonResult doUpdateMenu(@RequestBody SysMenu  menu){
        sysMenuService.updateMenu(menu);
        return new JsonResult("Update ok");
    }
    @PostMapping
    /**@RequestBody描述了这个方法的参数以后他才可以接收我们客户端提交的json格式的数据*/
    public JsonResult doSaveMenu( @RequestBody SysMenu menu){
        sysMenuService.saveMenu(menu);
        return new JsonResult("Save ok");
    }
    @GetMapping("treeNodes")

    public JsonResult doFindMenuTreeNodes(){
        return new JsonResult(sysMenuService.findMenuTreeNodes());
    }
    @GetMapping

    public JsonResult doFindMenus(){
        return new JsonResult(sysMenuService.findMenus());
    }
}

